import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from ddt import ddt,file_data
from Page3 import Page3

@ddt()
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        # 打开谷歌浏览器
        self.driver = webdriver.Chrome()
        # 窗口最大化
        self.driver.maximize_window()
        print('start case')

    def tearDown(self) -> None:
        # 退出
        self.driver.quit()
        time.sleep(5)
        print('case end')

    @file_data(r'D:\gao6-2210\yuekaopo\data.yaml')

    def test_something(self,username,password,pd):
        if pd == '正确':
            po = Page3(self.driver)
            # 获取网址
            po.open_url('http://localhost:8081/xklogin')
            time.sleep(3)

            po.username(username)
            time.sleep(3)
            po.password(password)
            time.sleep(3)
            po.login()
            time.sleep(3)
            po.sure()
            time.sleep(8)
            dy1 = self.driver.find_element(By.XPATH,
                                           '/html/body/div[1]/div/section/section/main/form/div/div[2]/div/div/button[3]').text
            print(f'断言1的值:{dy1}')
            dy2 = self.driver.find_element(By.XPATH,
                                           '/html/body/div[1]/div/section/section/main/div[1]/form/div[2]/div[3]/div/div/button').text
            print(f'打印断言2的值:{dy2}')
            self.assertNotIn(dy1, '刷新')
            self.assertNotEqual(dy2, '搜索')
        else:
            po = Page3(self.driver)
            # 获取网址
            po.open_url('http://localhost:8081/xklogin')
            time.sleep(3)

            po.username(username)
            time.sleep(3)
            po.password(password)
            time.sleep(3)
            po.login()
            time.sleep(3)
            po.sure()
            time.sleep(8)



if __name__ == '__main__':
    unittest.main()
